package com.itheima.leyou.controller;

import com.itheima.leyou.service.UserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class UserLoginController {
    @Autowired
    private UserAuthService userAuthService;


    /**
     * 对外提供登录授权服务，接收用户名和密码，生成JWT
     * 登录授权
     * @param username
     * @param password
     * @param response
     * @return
     */
    @PostMapping("/login")
    public ResponseEntity<Void> login(
            @RequestParam("username") String username,
            @RequestParam("password") String password,
            HttpServletResponse response){
        userAuthService.login(username,password,response);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();

    }
}
